package com.mida.bms.report.service.impl;

import com.alibaba.druid.sql.visitor.functions.If;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.mida.bms.report.entity.DocReportServiceLock;
import com.mida.bms.report.entity.DocStructTemplateInfo;
import com.mida.bms.report.mapper.DocReportServiceLockMapper;
import com.mida.bms.report.service.DocReportServiceLockService;
import com.mida.bms.report.service.SoidService;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.mida.tool.common.result.BaseResult.buildActionSuccess;
import static com.mida.tool.common.result.BaseResult.buildListSuccess;

/**
 * @ClassName: DocReportServiceLockServiceImpl
 * @Description: TODO
 * @Author: wang xiao le
 * @Date: 2021/7/28 10:56
 **/
@Service
@Transactional
@Slf4j
public class DocReportServiceLockServiceImpl implements DocReportServiceLockService {

    @Autowired
    private DocReportServiceLockMapper docReportServiceLockMapper;

    @Autowired
    private SoidService soidService;

    @Override
    public ActionResult insert(DocReportServiceLock docReportServiceLock) {

        ActionResult actionResult = new ActionResult();

        if (ObjectUtils.isEmpty(docReportServiceLock.getRequestSoid())) {
            actionResult.setStatus(HttpStatus.BAD_REQUEST.value());
            actionResult.setMessage("申请单标识不能为空");
            return actionResult;
        }
        if (ObjectUtils.isEmpty(docReportServiceLock.getExamCheckSoid())) {
            actionResult.setStatus(HttpStatus.BAD_REQUEST.value());
            actionResult.setMessage("检查号不能为空");
            return actionResult;
        }
        Long soid = soidService.getSoid();
        docReportServiceLock.setReportServiceLockSoid(soid);
        docReportServiceLockMapper.insertSelective(docReportServiceLock);
        soidService.insertOid(soid, 4);
        buildActionSuccess(actionResult);
        return actionResult;
    }

    @Override
    public ListResult<DocReportServiceLock> select(DocReportServiceLock docReportServiceLock) {
        ListResult<DocReportServiceLock> result = new ListResult<>();
        DocReportServiceLock docReportLock = docReportServiceLockMapper.select(docReportServiceLock);
        buildListSuccess(result, docReportLock);
        return result;
    }

    @Override
    public ActionResult delete(DocReportServiceLock docReportServiceLock) {
        ActionResult actionResult = new ActionResult();

        int result = docReportServiceLockMapper.delete(docReportServiceLock);
        buildActionSuccess(actionResult);
        return actionResult;
    }

    @Override
    public ListResult<List<DocReportServiceLock>> selectLockList(List<DocReportServiceLock> selectLockList) {
        ListResult< List<DocReportServiceLock>> result = new ListResult<>();
//        List<DocReportServiceLock> lockList = docReportServiceLockMapper.selectLockList(selectLockList);
        List<DocReportServiceLock> lockList = docReportServiceLockMapper.selectLockList(selectLockList);
        buildListSuccess(result, lockList);
        return result;
    }
}
